package cool.taomu.box.test

import com.google.inject.servlet.GuiceFilter
import cool.taomu.box.tomcat.ITomcatFilter
import javax.inject.Provider
import org.apache.tomcat.util.descriptor.web.FilterDef
import org.apache.tomcat.util.descriptor.web.FilterMap
import org.slf4j.LoggerFactory

class GJerseyTocamtConfig implements Provider<ITomcatFilter>  {
	val static LOG = LoggerFactory.getLogger(GJerseyTocamtConfig);

	override get() {
		LOG.info("加载tomcat filter")
		return new ITomcatFilter() {
			override filterDefs() {
				var defs = new FilterDef();
				defs.filterName = "guice"
				defs.filterClass = GuiceFilter.name;
				return #[defs]
			}

			override filterMaps() {
				var maps = new FilterMap;
				maps.filterName = "guice"
				maps.addURLPattern("/*")
				return #[maps]
			}

			override listeners() {
				return #[MyGuiceServletContextListener];
			}
		}

	}

}
